home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Demos / AppMaker 2.0b3 / Demo AppMaker 1.5 / Demo AppMaker™ / Demo AppMaker™.rsrc / TmpC_151_Menu.File < prev    next >
Encoding:
Text File  |  1992-04-08  |  4.9 KB  |  261 lines

  1. /* %filename% */
  2. /* Created %date% %time% by AppMaker */
  3.  
  4. #include <Types.h>
  5. #include <Quickdraw.h>
  6. #include <Controls.h>
  7. #include <Dialogs.h>
  8. #include <Events.h>
  9. #include <Lists.h>
  10. #include <Menus.h>
  11. #include <TextEdit.h>
  12. #include <Desk.h>
  13. #include <Packages.h>
  14. #include <ToolUtils.h>
  15. %if lang = AUX%
  16.     #include "resdefs.h"
  17.     #include "dispatcher.h"
  18.     #include "miscellany.h"
  19. %else%
  20.     #include "ResourceDefs.h"
  21.     #include "Dispatcher.h"
  22.     #include "Miscellany.h"
  23. %endif%
  24. #include "Globals.h"
  25. %for each menuItem gen includeDialog%
  26. #include "%appName%Data.h"
  27. #include "%menuname%M.h"
  28.  
  29. #define dialogTop        75                                   
  30. #define dialogLeft        85
  31.  
  32. %if lang = MPW%
  33.     #pragma segment %menuname% 
  34.  
  35. %end if%
  36.  
  37. short            numOpenTypes;
  38. SFTypeList        openTypeList;
  39.  
  40. static void        CloseAppWindow    (void);
  41. %for each menuitem gen doItemProto%
  42.  
  43. /*----------*/
  44. void Init%MenuName%M (void)
  45. {
  46.     %if lang = AUX%
  47.         numOpenTypes = 2;
  48.         openTypeList [0] = kFileType;
  49.         openTypeList [1] = 'A/UX';
  50.     %else%
  51.         numOpenTypes = 1;
  52.         openTypeList [0] = kFileType;
  53.     %endif%
  54. } /*Init%MenuName%M*/
  55.  
  56. /*----------*/
  57. Boolean OkToOpen (OSType    fType)
  58. {
  59.     short            i;
  60.     enum {searching, found, notFound}
  61.                     status;
  62.  
  63.     i = 0;
  64.     status = searching;
  65.     while (status == searching) {
  66.         if (i >= numOpenTypes) {
  67.             status = notFound;
  68.         } else {
  69.             if (fType == openTypeList [i]) {
  70.                 status = found;
  71.             } else {
  72.                 i++;
  73.             }
  74.         }
  75.     } /*while*/
  76.     return (status == found);
  77. } /*OkToOpen*/
  78.  
  79. /*----------*/
  80. static void DoNew (void)
  81. {
  82.     OpenWindows ("\p", 0, 0);
  83.     InitAppData ();
  84.  
  85. } /*DoNew*/
  86.  
  87. /*----------*/
  88. void OpenDoc    (Str255        fileName, 
  89.                  short        vRefNum)
  90. {
  91. /* This *should* be defined in an Apple interface file: */
  92. #define StationeryFlag    0x0800
  93.  
  94.     Boolean            isStationery;
  95.     FInfo            finderInfo;
  96.     short            fRefNum;
  97.  
  98.     isStationery = false;
  99.     if (GetFInfo (fileName, vRefNum, &finderInfo) == noErr) {
  100.         if ((finderInfo.fdFlags & StationeryFlag) != 0) {
  101.             isStationery = true;
  102.         }
  103.     }
  104.     if (OpenAppFile (vRefNum, fileName, &fRefNum)) {
  105.         if (isStationery) {
  106.             OpenWindows ("\p", 0, 0);
  107.             ReadAppFile (fRefNum);
  108.             CloseAppFile (fRefNum);
  109.         } else {
  110.             OpenWindows (fileName, vRefNum, fRefNum);
  111.             ReadAppFile (fRefNum);
  112.         }
  113.     }    
  114. } /*OpenDoc*/
  115.  
  116. /*----------*/
  117. static void DoOpen (void)
  118. {
  119.     Point            dialogOrigin;
  120.     SFReply            sfInfo;
  121.  
  122.     SetPt (&dialogOrigin, dialogLeft, dialogTop);
  123.     SFGetFile (dialogOrigin, "\p", nil, numOpenTypes, openTypeList, nil, &sfInfo);
  124.     if (sfInfo.good) {
  125.         OpenDoc (sfInfo.fName, sfInfo.vRefNum);
  126.     }
  127. } /*DoOpen*/
  128.  
  129. /*----------*/
  130. void OpenApp (void)
  131. {
  132.     DoNew ();
  133. } /*OpenApp*/
  134.  
  135. /*----------*/
  136. static void DoSaveAs (void)
  137. {
  138.     SFReply            sfInfo;
  139.     short            fRefNum;
  140.     StringHandle    prompt;
  141.     Str255            suggestion;
  142.     
  143.     prompt = GetString (SaveAsPromptID);
  144.     suggestion [0] = 0;
  145.  
  146.     if (CreateFile (&sfInfo, *prompt, suggestion, kSignature, kFileType)) {
  147.         CloseAppFile (cur->fileNum);
  148.         if (OpenAppFile (sfInfo.vRefNum, sfInfo.fName, &fRefNum)) {
  149.             SetWTitle (curWindow, sfInfo.fName);
  150.             cur->fileNum = fRefNum;
  151.             cur->volNum = sfInfo.vRefNum;
  152.             WriteAppFile (cur->fileNum);
  153.             cur->dirty = false;
  154.         } else { /*should never happen*/
  155.             SetWTitle (curWindow, "\p???");
  156.             cur->fileNum = 0;
  157.             cur->volNum = 0;
  158.         }
  159.     }
  160. } /*DoSaveAs*/
  161.  
  162. /*----------*/
  163. static void DoSave (void)
  164. {
  165.     if (cur->fileNum == 0) {
  166.         DoSaveAs ();
  167.     } else {
  168.         WriteAppFile (cur->fileNum);
  169.         cur->dirty = false;
  170.     }
  171. } /*DoSave*/
  172.  
  173. /*----------*/
  174. static void CloseAppWindow (void)
  175. {
  176.     enum {saveItem = 1, cancelItem, discardItem};
  177.     
  178.     Str255            curTitle;
  179.     short            itemNum;
  180.     Boolean            okay;
  181.  
  182.     okay = true;
  183.     SetInfo (FrontWindow ());
  184.     if (cur->dirty) {
  185.         GetWTitle (curWindow, curTitle);
  186.         ParamText (curTitle, "\p", "\p", "\p");
  187.         InitCursor ();
  188.         itemNum = Alert (SaveID, nil);
  189.         switch (itemNum) {
  190.             case saveItem:
  191.                     DoSave ();
  192.                     okay = !errorFlag;
  193.                 break;
  194.             case discardItem:
  195.                    /*Do nothing*/;
  196.                 break;
  197.             case cancelItem:
  198.                     errorFlag = true;
  199.                     okay = false;
  200.                 break;
  201.         } /*switch*/
  202.     }
  203.     if (okay) {
  204.         DisposeAppData ();
  205.         if (cur->windowKind == 1) {        /* 1st or only window in set */
  206.             CloseAppFile (cur->fileNum);
  207.         }
  208.         CloseCurWindow ();
  209.     }
  210. } /*CloseAppWindow*/
  211.  
  212. /*----------*/
  213. void DoClose (void)
  214. {
  215.     WindowPeek        frontPeek;
  216.  
  217.     errorFlag = false;
  218.  
  219.     frontPeek = (WindowPeek) FrontWindow ();
  220.     if (frontPeek->windowKind < 0) {
  221.         CloseDeskAcc (frontPeek->windowKind);
  222.     } else if (frontPeek->windowKind == dialogKind) {
  223.         CloseModelessDialog (FrontWindow ());
  224.     } else {
  225.         CloseAppWindow ();
  226.     }
  227. } /*DoClose*/
  228.  
  229. /*----------*/
  230. void DoQuit (void)
  231. {
  232.     Boolean            quitting;                             
  233.  
  234.     quitting = true;
  235.     while (quitting && (FrontWindow () != nil)) {
  236.         SystemTask ();
  237.         DoClose ();
  238.         if (errorFlag) {
  239.             quitting = false;
  240.         }
  241.     } /*while*/
  242.     
  243.     if (quitting) {
  244.         quittingTime = true;
  245.     }
  246. } /*DoQuit*/
  247.  
  248. %for each menuitem gen doItem%
  249. /*----------*/
  250. void Do%MenuName%    (short        itemNr)
  251. {
  252.     errorFlag = false;
  253.     
  254.     switch (itemNr) {
  255.         %for each menuitem gen handleitem%
  256.  
  257.     } /*switch*/
  258. } /*Do%MenuName%*/
  259.  
  260. /* %menuname% */
  261.